<?php

  require_once "function2.php";

  $mesg1="\n查無近一年內 creatinine 資料";

  ob_start();
  if($_GET["id"]==NULL){
    $id=$_POST["id"];
  }else $id=$_GET["id"];
  
  if(!isset($id)) exit;
    
  $name=getName($id);
  if($name['name']==NULL) exit('無此病歷號！');
  //$caseno=getLabCaseno($id);
  $age=ageOI($name['birthdate'],date('Y.m.d',time()));
  echo $id.' '.$name['name'].' '.$name['gender'].' ';

  //處理不同年紀顯示
  if($age['y']==0&&$age['m']>=1) echo "<font color=#ff0000>".$age['m'].'個月'.$age['d'].'天';
  if($age['y']==0&&$age['m']==0) echo "<font color=#ff0000>".$age['d'].'天';
  if($age['y']<=5&&$age['y']>=1) echo $age['y'].'歲'.$age['m'].'個月';
  if($age['y']>=70) echo $age['y'].'歲';
  if($age['y']>=6&&$age['y']<70) echo $age['y'].'歲';

  //處理creatinine及GFR
  $labarray=array();
  $labstring=array("HB","PLT","WBC","PT","PT INR","PTT","UN","CRE","AMY","AST","ALT","ALP","T-BIL","D-BIL","GGT","r-GT","Alb","Lipase","Alpha-Fetoprotein");
  foreach($labstring as $element){
  $caseno=getLabCaseno($id,$element);
  if(is_string($caseno)){
    $cr=substr($caseno,17,strlen($caseno)-17);
    $labarray["$element"].=$caseno;
  }
  if(is_array($caseno)&&!empty($caseno)){
    $cre=getLabDept($id,$caseno,$element);
    if($cre!=NULL){
      $labarray["$element"].=$cre;
    }
  }
  }

  $out=ob_get_clean();
  ob_end_clean();
  $out=mb_convert_encoding($out,"big5","utf-8");
  echo $out;
  print_r($labarray);
?>
